//
//  CPSCTagNameDemoVC.m
//  CollTest
//
//  Created by codew on 11/15/21.
//

#import "CPSCTagNameDemoVC.h"
#import "CPSCMarkAttributedStringTools.h"
@interface CPSCTagNameDemoVC ()

@property (weak, nonatomic) IBOutlet UILabel *lblName;


@end

@implementation CPSCTagNameDemoVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.lblName.font = [UIFont systemFontOfSize:16];
    
    self.lblName.attributedText = [CPSCMarkAttributedStringTools attributedStringWithMarkTitle:@"限时" contentText:@" cornerRadius要设置成所生成的图片的3倍，也就是说要生成一个三倍图，否则生成的图片会虚，同学们可以试一试。"];
    
    
    
    self.lblName.attributedText = [CPSCMarkAttributedStringTools attributedStringOriginalPrice:@"688.00" unitString:@"美元" lineContainUnit:NO];
    
//    NSString *titleString = @"我是标题！我是标题！我是标！我是标题！创建这个Label的时候，frame，font，cornerRadius要设置成所生成的图片的3倍，也就是说要生成一个三倍图，否则生成的图片会虚，同学们可以试一试。";
//    //创建  NSMutableAttributedString 富文本对象
//    NSMutableAttributedString *maTitleString = [[NSMutableAttributedString alloc] initWithString:titleString];
//    //创建一个小标签的Label
//    NSString *aa = @"限时秒杀";
//    CGFloat aaW = 12*aa.length +16;
//    UILabel *aaL = [UILabel new];
//    aaL.frame = CGRectMake(0, 0, aaW*3, 16*3);
//    aaL.text = aa;
//    aaL.font = [UIFont boldSystemFontOfSize:12*3];
//    aaL.textColor = [UIColor whiteColor];
//    aaL.backgroundColor = [UIColor redColor];
//    aaL.clipsToBounds = YES;
//    aaL.layer.cornerRadius = 3*3;
//    aaL.textAlignment = NSTextAlignmentCenter;
//    //调用方法，转化成Image
//    UIImage *image = [self imageWithUIView:aaL];
//    //创建Image的富文本格式
//    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
//    attach.bounds = CGRectMake(0, -2.5, aaW, 16); //这个-2.5是为了调整下标签跟文字的位置
//    attach.image = image;
//    //添加到富文本对象里
//    NSAttributedString * imageStr = [NSAttributedString attributedStringWithAttachment:attach];
//    [maTitleString insertAttributedString:imageStr atIndex:0];//加入文字前面
//    //[maTitleString appendAttributedString:imageStr];//加入文字后面
////    [maTitleString insertAttributedString:imageStr atIndex:4];//加入文字第4的位置
//
//
//    self.lblName.attributedText = maTitleString;
//    //注意 ：创建这个Label的时候，frame，font，cornerRadius要设置成所生成的图片的3倍，也就是说要生成一个三倍图，否则生成的图片会虚，同学们可以试一试。
    
    
    
    

}
//view转成image
//- (UIImage*) imageWithUIView:(UIView*) view{
//    view.backgroundColor = UIColor.clearColor;
//    UIView * viewSuper = [[UIView alloc] initWithFrame:CGRectMake(0, 0, view.width, view.height)];
//    viewSuper.layer.cornerRadius = 3*3;
//
//    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
//    gradientLayer.frame = viewSuper.bounds;
//    // 设置渐变颜色数组
//    gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#ED6242"].CGColor,
//                             (__bridge id)[UIColor colorWithHexString:@"#ED2929"].CGColor];
//    // 设置渐变起始点
//    gradientLayer.startPoint = CGPointMake(.0, .0);
//    // 设置渐变结束点
//    gradientLayer.endPoint = CGPointMake(.0, 1.0);
//
//    gradientLayer.cornerRadius = 3*3;
//    // 设置渐变颜色分布区间，不设置则均匀分布
//    // gradientLayer.locations = @[@(0.0), @(1.0)];
//    // 设置渐变类型，不设置则按像素均匀变化
//    // gradientLayer.type = kCAGradientLayerAxial;// 按像素均匀变化
//    [viewSuper.layer addSublayer:gradientLayer];
//
//
//    view.frame = viewSuper.bounds;
//    [viewSuper addSubview:view];
//
//    UIGraphicsBeginImageContext(viewSuper.bounds.size);
//    CGContextRef ctx = UIGraphicsGetCurrentContext();
//    [viewSuper.layer renderInContext:ctx];
//    UIImage* tImage = UIGraphicsGetImageFromCurrentImageContext();
//    UIGraphicsEndImageContext();
//    return tImage;
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
